import * as vscode from 'vscode';
import * as path from 'path';

export class Bundle extends vscode.TreeItem {
    constructor(
        public readonly bundleId: number,
        public readonly label: string,
        public readonly address: string,
        public readonly collapsibleState: vscode.TreeItemCollapsibleState
    ) {
        super(label, collapsibleState);
        this.bundleId = bundleId;
        this.address = address;
        this.tooltip = `${this.label}`;
        this.contextValue = 'Bundle';
    }

    iconPath = {
        light: path.join(__filename, '..', '..', 'resources', 'cloud.svg'),
        dark: path.join(__filename, '..', '..', 'resources', 'cloud.svg')
    };
}

export default class BundleProvider implements vscode.TreeDataProvider<Bundle>{
    private _onDidChangeTreeData: vscode.EventEmitter<Bundle | undefined | null | void> = new vscode.EventEmitter<Bundle | undefined | null | void>();
    readonly onDidChangeTreeData: vscode.Event<Bundle | undefined | null | void> = this._onDidChangeTreeData.event;

    private bundles: Bundle[] = [];
  
    refresh(): void {
      this._onDidChangeTreeData.fire();
    }

    constructor() {}

    getTreeItem(element: Bundle): Bundle {
       return element;
    }

    getChildren(element?: Bundle): Thenable<Bundle[]> {
        if(!element) {
            return Promise.resolve(this.bundles);
        } else {
           return Promise.resolve([]);
        }
    }
}